package com.uchengwang.ui.cm_ui.umsg.adapter;

import android.content.Context;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.ui.cm_ui.umsg.bean.MoreConditionBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/12/14.
 */

public class MoreConditionAdapter extends RecyclerView.Adapter<MoreConditionAdapter.MoreVH>{
    private Context context;
    private List<MoreConditionBean> list = new ArrayList<>();
    public MoreConditionAdapter(Context context, List<MoreConditionBean> list){
        this.context =context;
        this.list = list;
    }

    @Override
    public MoreVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_more_condition_item, parent, false);
        return new MoreVH(view);
    }

    @Override
    public void onBindViewHolder(final MoreVH holder, int position) {
        final MoreConditionBean bean = list.get(position);
        holder.box.setChecked(bean.isCheck());

        holder.tv.setText(bean.getTitle());

        holder.ln.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for (MoreConditionBean b : list){
                    b.setCheck(false);
                }
                bean.setCheck(true);
                notifyDataSetChanged();
            }
        });


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MoreVH extends RecyclerView.ViewHolder {
        private LinearLayout ln;
        private AppCompatCheckBox box;
        private TextView tv;

        public MoreVH(View itemView) {
            super(itemView);

            AutoUtils.autoSize(itemView);

            ln = (LinearLayout) itemView.findViewById(R.id.condition_ln);
            box = (AppCompatCheckBox) itemView.findViewById(R.id.condition_check);
            tv = (TextView) itemView.findViewById(R.id.condition_tv);

        }
    }
}
